<?php
/**
 * Created by PhpStorm.
 * User: wxp
 * 日期: 2019/1/23
 * 时间: 14:47
 */

namespace app\modules\admin\controllers;

use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\web\Controller as BaseController;

class Controller extends BaseController
{
    public function behaviors()
    {
//        return parent::behaviors();
        return [
            'access' => [
                'class' => AccessControl::className(),
                'user' => 'admin',
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
            ],
        ];
    }

    public function analyErr($firstErrors)
    {
        if (!is_array($firstErrors) || empty($firstErrors))
        {
            return false;
        }

        $errors = array_values($firstErrors)[0];

        return $errors ?? '未捕获到错误信息';
    }
    public function message($msgText, $skipUrl, $msgType = null)
    {
        $msgType = $msgType ?? 'success';
        !in_array($msgType, ['success', 'error', 'info', 'warning']) && $msgType = 'success';

        Yii::$app->getSession()->setFlash($msgType, $msgText);

        return $skipUrl;
    }
}